﻿package {
	import flash.display.*;
	import flash.external.*;
	import flash.net.*;
	import flash.text.*;
	import flash.events.*;
	public class LC extends Sprite {
		public static const LISTENER:String = "listener";
		public static const SENDER:String = "sender";
		//
		public var lc_conn:LocalConnection;
		public var name_conn:String;
		//
		public var vars:Object;
		public var lc:String = "connect_name";
		public var ondata:String = "ondata";
		public var onstate:String = "onstate";
		public var onloaded:String = "onloaded";
		public function LC():void {
			vars = root.loaderInfo.parameters;
			getVars(["lc", "ondata", "onstate", "onloaded"]);
			//
			lc_conn = new LocalConnection();
			lc_conn.allowDomain("*");
			lc_conn.client = this;
			lc_conn.addEventListener(AsyncErrorEvent.ASYNC_ERROR, evt);
			lc_conn.addEventListener(SecurityErrorEvent.SECURITY_ERROR, evt);
			if (ExternalInterface.available) {
				ExternalInterface.addCallback("sendData", sendData);
			}
		}
		
		public function evt(e:Event):void {
		}
		public function sendData(... rest):void {
		}
		public function getData(... rest):void {
		}
		
		public function onStatus(e:StatusEvent):void {
			eicall(onstate, e.level);
        }
		
		public function eicall(fn:String, dat:Object = ""):void {
			if (ExternalInterface.available && fn) {
				ExternalInterface.call(fn, dat);
			}
		}
		
		public function getVars(arr:Array):void {
			for each (var k:String in arr) {
				if (vars.hasOwnProperty(k)) {
					this[k] = vars[k];
				}
			}
		}
		
	}
}